//
//  LZMyChangeInfoView.m
//  laziz_Consumer
//
//  Created by xbn_iMac on 2017/3/23.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZMyChangeInfoView.h"
#import "LZMyChangeNickNameView.h"
#import "Masonry.h"

@interface LZMyChangeInfoView ()

@property (nonatomic, assign) BOOL isSecure;

@end

@implementation LZMyChangeInfoView

- (instancetype)initWithTextFieldIsSecure:(BOOL)isSecure {
    self = [super init];
    if (self) {
        self.isSecure = isSecure;
    }
    return self;
}

- (void)setType:(LZ_CHANGEINFO_VIEW_TYPE)type {
    _type = type;
    
    [self configView];
    
    [self addAutoLayout];
}

- (void)configView {
    
    if (self.type == LZ_CHANGEINFO_VIEW_TYPE_SET) {
        [self addSubview:self.lzNewView];
        [self.lzNewView addSubview:self.lzNewLabel];
        [self.lzNewView addSubview:self.lzNewTextField];
    }
    else {
        
        [self addSubview:self.lzOldView];
        [self addSubview:self.lzNewView];
        
        [self.lzOldView addSubview:self.lzOldLabel];
        [self.lzOldView addSubview:self.lzOldTextField];
        
        [self.lzNewView addSubview:self.lzNewLabel];
        [self.lzNewView addSubview:self.lzNewTextField];
    }
    
    [self addSubview:self.subLabel];
}

- (void)addAutoLayout {
    
    WS(weakSelf);
    
    if (self.type == LZ_CHANGEINFO_VIEW_TYPE_SET) {
        
        [self.lzNewView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(55);
        }];
        
        [self.lzNewLabel makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(10);
            make.centerY.mas_equalTo(weakSelf.lzNewView.centerY);
        }];
        
        [self.lzNewTextField makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(weakSelf.lzNewLabel.trailing).with.offset(10);
            make.trailing.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
        
        [self.subLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(weakSelf.lzNewView.mas_bottom).with.offset(10);
            make.leading.mas_equalTo(10);
            make.trailing.mas_equalTo(-10);
            make.height.mas_equalTo(15);
        }];
    }
    else {
        
        [self.lzOldView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(55);
        }];
        
        [self.lzNewView makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(weakSelf.lzOldView.mas_bottom).with.offset(10);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(55);
        }];
        
        [self.subLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(weakSelf.lzNewView.mas_bottom).with.offset(10);
            make.leading.mas_equalTo(10);
            make.trailing.mas_equalTo(-10);
            make.height.mas_equalTo(15);
        }];
        
        [self.lzOldLabel makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(10);
            make.centerY.mas_equalTo(weakSelf.lzOldView.centerY);
        }];
        
        [self.lzOldTextField makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(weakSelf.lzOldLabel.trailing).with.offset(10);
            make.trailing.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
        
        [self.lzNewLabel makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(10);
            make.centerY.mas_equalTo(weakSelf.lzNewView.centerY);
        }];
        
        [self.lzNewTextField makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(weakSelf.lzNewLabel.trailing).with.offset(10);
            make.trailing.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
    }
}

#pragma mark - Setter/Getter

- (UIView *)lzOldView {
    
    if (_lzOldView == nil) {
        _lzOldView = [[UIView alloc] init];
        _lzOldView.backgroundColor = UIColorFromRGB(0xffffff, 1);
    }
    
    return _lzOldView;
}

- (UILabel *)lzOldLabel {
    
    if (_lzOldLabel == nil) {
        _lzOldLabel = [[UILabel alloc] init];
        
        _lzOldLabel.textColor   = UIColorFromRGB(0x333333, 1);
        _lzOldLabel.font        = [UIFont systemFontOfSize:15];
    }
    
    return _lzOldLabel;
}

- (LZMyChangeNickNameView *)lzOldTextField {
    
    if (_lzOldTextField == nil) {
        _lzOldTextField = [[LZMyChangeNickNameView alloc] initWithIsPassword:self.isSecure];
    }
    
    return _lzOldTextField;
}

- (UIView *)lzNewView {
    
    if (_lzNewView == nil) {
        _lzNewView = [[UIView alloc] init];
        _lzNewView.backgroundColor = UIColorFromRGB(0xffffff, 1);
    }
    
    return _lzNewView;
}

- (UILabel *)lzNewLabel {
    
    if (_lzNewLabel == nil) {
        _lzNewLabel = [[UILabel alloc] init];
        _lzNewLabel.textColor   = UIColorFromRGB(0x333333, 1);
        _lzNewLabel.font        = [UIFont systemFontOfSize:15];
    }
    
    return _lzNewLabel;
}

- (LZMyChangeNickNameView *)lzNewTextField {
    
    if (_lzNewTextField == nil) {
        _lzNewTextField = [[LZMyChangeNickNameView alloc] initWithIsPassword:self.isSecure];
    }
    
    return _lzNewTextField;
}

- (UILabel *)subLabel {
    
    if (_subLabel == nil) {
        _subLabel = [[UILabel alloc] init];
        _subLabel.text      = LZLocalizedString(@"enter_password_6_chart", @"");//@"Please enter at least 6 characters";
        _subLabel.textColor = UIColorFromRGB(0xbababa, 1);
        _subLabel.font      = [UIFont systemFontOfSize:12];
    }
    
    return _subLabel;
}


@end
